package com.ruoyi.work.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.work.mapper.BmSellermechanismMapper;
import com.ruoyi.work.domain.BmSellermechanism;
import com.ruoyi.work.service.IBmSellermechanismService;

/**
 * 客户关系管理Service业务层处理
 * 
 * @author sj
 * @date 2023-08-02
 */
@Service
public class BmSellermechanismServiceImpl implements IBmSellermechanismService
{
    @Autowired
    private BmSellermechanismMapper bmSellermechanismMapper;

    /**
     * 导出excel表
     * @param bmSellermechanism
     * @return
     */
    @Override
    public List<BmSellermechanism> selectBmSellermechanismList(BmSellermechanism bmSellermechanism) {
        return bmSellermechanismMapper.selectBmSellermechanismList(bmSellermechanism);
    }

    /**
     * 新增客户关系管理
     * 
     * @param bmSellermechanism 客户关系管理
     * @return 结果
     */
    @Override
    public int insertBmSellermechanism(BmSellermechanism bmSellermechanism)
    {
        bmSellermechanism.setCreateTime(DateUtils.getNowDate());
        bmSellermechanism.setIsDeleted(Long.parseLong("0"));
        List<Map<String,Integer>> list = bmSellermechanismMapper.getListHostory();
        for (int i = 0; i <list.size(); i++) {
            Map<String,Integer> map = list.get(i);
            Long sellerId = Long.valueOf(map.get("seller_id").toString());
            Long mechanismId = Long.valueOf(map.get("mechanism_id").toString());
            boolean s_id = bmSellermechanism.getSellerId().equals(sellerId);
            boolean m_id = bmSellermechanism.getMechanismId().equals(mechanismId);
            System.out.println(s_id);
            System.out.println(m_id);
            if (s_id && m_id ){
                throw new RuntimeException("该合作关系已经存在!");
            }
        }
        return bmSellermechanismMapper.insertBmSellermechanism(bmSellermechanism);
    }

    /**
     * 批量删除客户关系管理
     * 
     * @param ids 需要删除的客户关系管理主键
     * @return 结果
     */
    @Override
    public int deleteBmSellermechanismByIds(Long[] ids)
    {
        return bmSellermechanismMapper.deleteBmSellermechanismByIds(ids);
    }

    /**
     * 删除客户关系管理信息
     * 
     * @param id 客户关系管理主键
     * @return 结果
     */
    @Override
    public int deleteBmSellermechanismById(Long id)
    {
        return bmSellermechanismMapper.deleteBmSellermechanismById(id);
    }

    /**
     * 查询客户关系管理列表
     *
     * @param bmSellermechanism 客户关系管理
     * @return 客户关系管理
     */
    @Override
    public List<Map<String, Object>> listSellermechanism(BmSellermechanism bmSellermechanism) {
        return bmSellermechanismMapper.listSellermechanism(bmSellermechanism);
    }

    /**
     * 查询机构id和名称
     * @return
     */
    @Override
    public List<Map<String, Object>> getMechanismName() {
        return bmSellermechanismMapper.getMechanismName();
    }
    /**
     * 查询商家id和名称
     * @return
     */
    @Override
    public List<Map<String, Object>> getBusinessName() {
        return bmSellermechanismMapper.getBusinessName();
    }
}
